<template>
  <div class="persondata">
    <div class="line">
      <span>|</span>
      <span>{{ cropName }}</span>
    </div>
    <div class="header">
      <div class="left">
        <el-input v-model="input" placeholder="请输入姓名" style="margin-right:2%" />
        <el-button size="medium" @click="search">搜索</el-button>
      </div>
      <div class="right">
        <el-button type="primary" size="small" icon="el-icon-arrow-left" @click="goback">返回</el-button>
      </div>
    </div>
    <div class="content">
      <el-table
        ref="multipleTable"
        v-loading="listLoading"
        stripe
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          type="selection"
          width="77"
        />
        <el-table-column
          label="序号"
          width="180"
        >
          <template slot-scope="scope">{{ scope.$index+1 }}</template>
        </el-table-column>
        <el-table-column
          prop="studentName"
          label="姓名"
          width="180"
        />
        <el-table-column
          prop="className"
          label="班级"
          width="180"
        />
        <el-table-column
          prop="gradeName"
          label="年级"
          width="180"
          show-overflow-tooltip
        />
        <el-table-column
          prop="lastModifiedTime"
          label="最新提交时间"
          width="200"
          show-overflow-tooltip
        />
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="handleLook(scope.$index, scope.row)"
            ><i class="el-icon-view" /></el-button>
            <el-button
              size="mini"
              type="text"
              @click="trainningReport(scope.$index, scope.row)"
            ><i class="el-icon-tickets" /></el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import { getAllstudentData } from '@/api/dataReport'
export default {
  name: 'Persondata',
  data() {
    return {
      role: '',
      input: '',
      classId: '',
      cropId: '',
      cropName: '',
      tableData: [],
      multipleSelection: [],
      listLoading: true
    }
  },
  created() {
    this.role = this.$store.getters.roles[0]
    this.cropName = this.$store.getters.cropName
    const { cropId, classId } = this.$route.params
    this.cropId = cropId
    this.classId = classId
    const query = {
      classId: this.classId,
      cropId: this.cropId
    }
    this.getAllstudentData(query)
  },
  methods: {
    goback() {
      this.$router.go(-1)
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    handleLook(index) { // 查看个人数据
      const data = {
        cropId: this.cropId,
        studentId: this.tableData[index].studentId
      }
      this.$router.push(`/trainning/persondata/${this.cropId}/${this.tableData[index].studentId}`)
    },
    trainningReport(index) { // 查看个人实训报告
      this.$router.push(`/trainning/teacherReport/${this.cropId}/${this.tableData[index].studentId}`)
    },
    getAllstudentData(query) {
      getAllstudentData(query).then(res => {
        this.tableData = res.data.records
        this.listLoading = false
      })
    },
    search() {
      this.listLoading = true
      const query = {
        classId: this.classId,
        cropId: this.cropId,
        studentName: this.input
      }
      this.getAllstudentData(query)
    }
  }
}
</script>
<style scoped>
    .line{
        width: 100%;
        color: #345E8F;
        font-size: 16px;
        margin-bottom: 1%;
    }
    span:first-child{
        font-weight: bold;
        margin-right: 1%;
        font-size: 18px;
    }
    .header{
        display: flex;
        justify-content: space-between;
        margin-bottom: 1%;
    }
    .left{
        display: flex;
        justify-content: flex-start;
    }
</style>
